  <template>
   <div class="father">
    <div class="container">
      <div class="box">
        <div class="switch">
          <div class="disabled" v-show="Distinguish">
            <el-button @click="groups_open" :disabled="groupLoopList2==null?true:false">强开</el-button>
            <el-button @click="groups_shut" :disabled="groupLoopList2==null?true:false">强关</el-button>
            <el-button @click="Enable_strategy" :disabled="groupLoopList2==null?true:false">启用策略</el-button>
            <el-button @click="Prohibit_strategy" :disabled="groupLoopList2==null?true:false">禁用策略</el-button>
            <el-button @click="MoreOperations" :disabled="groupLoopList2==null?true:false">{{mount}}</el-button>
          </div>
          <el-button size="small" @click="audioPlay">系统悬浮窗</el-button>
          <span v-show="Identification=='气象传感器'?false:true" class="show">
            <el-button size="small" v-show="!Distinguish " @click="jumap">{{Identification}}控制</el-button>
          </span>
        </div>
      </div>
      <el-dialog class="Popup" title="操作" :visible.sync="dialogVisible">
        <div class="search">
          <input type="text" v-model="search_input" placeholder="请输入搜索名称" />
          <el-button type="success" @click="d_search">搜索</el-button>
        </div>
        <div class="loopBox" v-for="(item,index) in groupLoopList2" :key="index">
          <div class="loop">
            <div class="title">
              <span>{{item.name}}</span>
              <span class="Full">
                <el-button type="success" @click="FullOpen(item)" title="打开此电箱下所有回路">全开</el-button>
                <el-button type="danger" @click="AllPass(item)" title="关闭此电箱下所有回路">全关</el-button>
              </span>
            </div>
            <div class="electric">
              <div class="states">
                <ul class="three">
                  <li v-for="(item1,index) in item.groupElecLoopRespDTOS" :key="index">
                    <span
                      :title="item1.name"
                    >{{item1.name.length>10?item1.name.substr(0,5)+"...":item1.name}}</span>
                    <div class="rigth">
                      <div>
                        <el-button
                          type="success"
                          @click="KAi(item1.id)"
                          :disabled="item1.isOnline=='离线'?true:false"
                        >开</el-button>
                        <el-button
                          type="danger"
                          @click="GUAN(item1.id)"
                          :disabled="item1.isOnline=='离线'?true:false"
                        >关</el-button>
                      </div>
                      <label v-if="item1.isOnline== '离线' ">{{item1.isOnline}}</label>
                      <label style="color:#09daba" v-else>{{item1.isOnline}}</label>
                      <label class="Contai_details" @click="detailed(item1)" title="点击查看状态详情">详情</label>
                    </div>
                  </li>
                </ul>
              </div>
            </div>
          </div>
        </div>
        <div class="pagesKG">
          <el-pagination
            small
            :current-page="pages"
            layout="prev, pager, next"
            :total="total"
            :page-size="2"
            @current-change="handleCurrentChange"
          ></el-pagination>
        </div>
      </el-dialog>
      <!-- 电学参数 -->
      <el-dialog title="电学信息" :visible.sync="ElectricalScience" width="460px">
        <table border="1px" cellspacing="0" cellpadding="0">
          <thead>
            <th></th>
            <th>电流(A)</th>
            <th>策略下发状态</th>
            <th>策略状态</th>
          </thead>
          <tbody>
            <tr>
              <td>A相</td>
              <td>{{electric.conA}}</td>
              <td rowspan="4">{{electric.aptIssueState}}</td>
              <td rowspan="4">{{electric.aptState}}</td>
            </tr>
            <tr>
              <td>B相</td>
              <td>{{electric.conB}}</td>
            </tr>
            <tr>
              <td>C相</td>
              <td>{{electric.conC}}</td>
            </tr>
            <tr>
              <td>总电流</td>
              <td>{{electric.conA+electric.conB+electric.conC}}</td>
            </tr>
          </tbody>
        </table>
      </el-dialog>
    </div>
  </div>
</template>
  <script>
import ht from "../../ht.js";
import { mapActions } from "vuex";
import { mapState } from "vuex";
import { mapMutations } from "vuex";
// import { mapGetters } from "vuex";
export default {
  data() {
    return {
      ElectricalScience: false,
      radio2: 0,
      dialogVisible: false,
      kg: true,
      kg1: false,
      Choice: 3,
      // 进线参数
      line: false,
      side: true,
      Illustrations: false,
      // icon:'el-icon-arrow-left',
      ts: false,
      arr: [
        { id: "1", force: 3 },
        { id: "2", force: 2 },
        { id: "3", force: 1 },
        { id: "4", force: 2 },
        { id: "5", force: 3 },
        { id: "6", force: 1 },
        { id: "7", force: 2 },
        { id: "8", force: 3 }
      ],
      arr1: [],
      search_input: "",
      pages: 1,
      electric: {},
      path: " ",
      displayerServiceUrl: "",
      wifiServiceUrl: "",
      cameraServiceUrl:""
    };
  },

  computed: {
    ...mapState("boxList", [
      "groupLoopList2",
      "PacketLoopID",
      "total",
      "Distinguish",
      "Identification",
      "mount"
    ]),
    newe() {
      return this.groupLoopList2.filter(v => {
        return v.name.startsWith(this.serch2);
      });
    }
  },
  mounted() {
    this.GETdisplayerServiceUrl();
    this.GETwifiServiceUrl()
    this.GETcameraServiceUrl()
  },

  methods: {
    // 用来以后查看回路的状态
    ...mapActions("boxList", ["loopList", "loopList2"]),
    ...mapMutations("boxList", ["page", "search"]),
    async url(url) {
      return await this.$http.get(
        "/api/threesuns/system/config/get?key=" + url
      );
    },
    // 显示屏地址请求
    GETdisplayerServiceUrl() {
      this.url("displayerServiceUrl")
        .then(res => {
          this.displayerServiceUrl = res.data.data.value;

        })
        .catch(err => {
          console.log(err);
        });
    },
    // wifi地址请求
    GETwifiServiceUrl() {
      this.url("wifiServiceUrl")
        .then(res => {
          this.wifiServiceUrl = res.data.data.value;
        })
        .catch(err => {
          console.log(err);
        });
    },
    GETcameraServiceUrl(){
      this.url("cameraServiceUrl").then(res=>{
        this.cameraServiceUrl=res.data.data.value
      })
    },
    jumap() {
      if (this.Identification == "显示屏") {
        window.open(
          this.displayerServiceUrl,
          "_blank",
          "toolbar=no, location=yes, directories=yes"
        );
      } else if (this.Identification == "WIFI-AP节点") {
        window.open(
         this.wifiServiceUrl,
          "_blank",
          "toolbar=no, location=yes, directories=yes"
        );
      } else if (this.Identification == "摄像头") {
              location.href = this.cameraServiceUrl
      } else if (this.Identification == "气象传感器") {
        window.open(
          "http://fanyi.youdao.com/",
          "_blank",
          "toolbar=no, location=yes, directories=yes"
        );
      }
    },
    // 启用策略
    Enable_strategy() {
      this.strategy(true);
      // this.$emit("del");
    },
    // 禁用策略
    Prohibit_strategy() {
      this.strategy(false);
      // this.$emit("del");
    },
    // 策略启用禁用封装
    strategy(data) {
      this.$http
        .post("/api/threesuns/map/appointment/enable", {
          groupId: this.PacketLoopID,
          enable: data
        })
        .then(res => {
          if (res.data.code == "200") {
            this.$message.success(res.data.message);
          } else {
            this.$message.error(res.data.message);
          }
        })
        .catch(err => {
          this.$message.error(err.data.message);
        });
    },
    // 全开
    FullOpen(e) {
      this.Full(e, true);
    },
    // 全关
    AllPass(e) {
      this.Full(e, false);
    },
    Full(e, state) {
      let arr = [];
      for (let i = 0; i < e.groupElecLoopRespDTOS.length; i++) {
        arr.push(e.groupElecLoopRespDTOS[i].id);
      }
      this.$http
        .post("/api/threesuns/map/control/loopControl", {
          loopIds: arr,
          on: state
        })
        .then(res => {
          if (res.data.code == "200") {
            this.$message.success(res.data.message);
          } else {
            this.$message.warning(res.data.message);
          }
        })
        .catch(err => {
          this.$message.error(err.data.message);
        });
    },
    // 强开
    groups_open() {
      this.fun(true);
    },
    // 强关
    groups_shut() {
      this.fun(false);
    },
    //当前组所有有开关
    fun(state) {
      this.$http
        .post("/api/threesuns/map/control/groupControl", {
          groupId: this.PacketLoopID,
          on: state
        })
        .then(res => {
          if (res.data.code == "200") {
            this.$message.success(res.data.message);
          } else {
            this.$message.warning(res.data.message);
          }
        })
        .catch(err => {
          this.$message.error(err.data.message);
        });
    },
    // 开电箱
    KAi(id) {
      let arr = [];
      arr.push(id);
      this.$http
        .post("/api/threesuns/map/control/loopControl", {
          loopIds: arr,
          on: true
        })
        .then(res => {
          if (res.data.code == "200") {
            this.$message.success(res.data.message);
            arr = [];
          } else {
            this.$message.error(res.data.message);
          }
        });
    },
    // 关电箱
    GUAN(id) {
      // this.$emit("del");
      let arr = [];
      arr.push(id);
      this.$http
        .post("/api/threesuns/map/control/loopControl", {
          loopIds: arr,
          on: false
        })
        .then(res => {
          if (res.data.code == "200") {
            this.$message.success(res.data.message);
            arr = [];
          } else {
            this.$message.error(res.data.message);
          }
        });
    },
    setpage() {
      this.pages = 1;
    },
    // 电箱搜索
    d_search() {
      this.pages = 1;
      this.page(1);
      this.search(this.search_input);
      this.loopList2();
    },
    handleCurrentChange(e) {
      this.pages = e;
      this.page(e);
      this.loopList2();
    },
    MoreOperations() {
      this.dialogVisible = true;
      // this.loopList2()
    },
    detailed(e) {
      this.electric = e;
      this.ElectricalScience = true;
    },
    Line_parameters() {
      this.line = !this.line;
    },
    close() {
      this.Illustrations = false;
    },
    fault() {},
    explain() {
      this.Illustrations = !this.Illustrations;
    },
    audioPlay() {
      this.$emit("playStatus");
    },
    BoxStrategy() {
      this.$router.push("/BoxStrategy");
    }
  }
};
</script>
  <style scoped>
* {
  box-sizing: border-box;
}
.icon-tushi {
  font-size: 20px;
}
.icon-danti {
  font-size: 18px;
}
.icon-tonggao {
  font-size: 20px;
}

.box {
  bottom: 70px;
  z-index: 2;
}
.item {
  margin-top: 8px;
  margin-left: 40px;
}
.left {
  width: 330px;
  height: 50px;
  float: left;
  background-color: rgba(0, 0, 0, 0.8);
  border: 1px solid #ffffff;
}
.left .el-button--small {
  padding: 6px 6px;
  border-radius: 50%;
  z-index: 2;
}
.switch {
  width: fit-content;
  background-color: rgba(0, 0, 0, 0.8);
  border: 1px solid #fff;
  text-align: center;
  margin: 0 auto;
  padding: 10px 40px 5px 40px;
}
.Illustrations {
  position: absolute;
  background-color: #fff;
  width: 180px;
  z-index: 2;
  bottom: 200px;
  left: 600px;
}
.Illustrations p {
  line-height: 30px;
  text-align: center;
  color: #fff;
  position: relative;
}
.Illustrations .el-icon-close {
  position: absolute;
  line-height: 30px;
  color: #fff;
  right: 10px;
}
.top {
  height: 30px;
  background-color: RGB(0, 66, 143);
}

.switch .el-radio {
  line-height: 50px;
  color: #0a7e7e;
}
/deep/ .switch .el-radio__input.is-checked + .el-radio__label {
  color: #0ac07e;
}
/deep/ .el-radio__input.is-checked .el-radio__inner {
  background: #0ac07e;
}
/deep/ .el-dialog {
  /* width: 550px; */
  width: fit-content;
}
/deep/ .el-dialog__body {
  overflow: hidden;
}
.switch .el-button {
  /* margin-left: 40px; */
  font-size: 12px;
  padding: 8px 16px;
  color: #fff;
  border-radius: 8px;
  background-color: RGBA(9, 218, 186, 230);
  margin-bottom: 5px;
}

/deep/ .switch .el-radio__inner {
  background-color: #0a7e7e;
}
/deep/ .rigth .el-radio__inner {
  background-color: #0a7e7e;
}
/deep/ .rigth .el-radio__label {
}
.container /deep/ .el-dialog__header {
  background-color: #0a7e7e;
}
.container /deep/ .el-dialog__title {
  color: #fff;
}

/deep/ .el-switch__label {
  color: #0a7e7e;
}
/deep/ .left .el-button {
  background-color: #0a7e7e;
}
.Popup {
  /* overflow: hidden; */
}
.loopBox {
  width: fit-content;
  padding: 0 5px;
}
.detailsBox {
  display: inline-block;
}
.loop {
  border: #0d111a 1px solid;
  margin-top: 10px;
}
.title {
  border-bottom: #0d111a 1px solid;
  height: 29px;
  color: #0d111a;
  line-height: 29px;
  padding-left: 20px;
  padding-right: 20px;
}
.title .el-switch {
  float: right;
  margin-top: 5px;
}
.electric {
  /* height: 228px; */
  /* overflow: hidden; */
  padding-top: 18px;
}
.states::-webkit-scrollbar {
  width: 3px;
  background-color: #0a7e7e;
}
.states::-webkit-scrollbar-track {
  background-color: #d6e2ed;
}
.states::-webkit-scrollbar-thumb {
  background: #0a7e7e;
}
.marking {
  float: left;
}
.states {
  /* width: 332px; */
  margin: auto;
  height: 220px;
  padding-top: 20px;
  /* padding-top: 6px 7px; */
  overflow: hidden;
  overflow-y: scroll;
}
.states ul {
  float: left;
  padding: 0 10px;
}
.states li span {
  display: inline-block;
  width: 133px;
  padding: 3px 10px;
  line-height: 33px;
  margin-left: 15px;
  border-radius: 8px;
  text-align: center;
  /* line-height: 28px; */
  color: #333;
  position: relative;
}
.individual {
  text-align: center;
  height: 34px;
  border-bottom: 1px #cccccc solid;
  line-height: 34px;
}
.individual i {
  width: 34px;
  text-align: center;
  margin-right: 5px;
}
.individual span {
  border-left: 1px #cccccc solid;
  text-align: center;
  display: inline-block;
  width: 143px;
  color: RGB(116, 116, 116);
  font-size: 12px;
}

.states span :hover span {
  color: #39ca64;
}
.states span i {
  width: 10px;
  position: absolute;
  border-top: 1px #3ccb66 solid;
  top: 13px;
  right: -11px;
}
.rigth {
  float: right;
  width: fit-content;
  /* height: 28px; */
  border-radius: 8px;
  line-height: 37px;
  text-align: center;
  padding: 0 18px;
}

.three li {
  margin-bottom: 10px;
  display: flex;
  border-radius: 12px;
   box-shadow:inset 0px 0px 5px 1px #e8e7e7;
}

.container .el-radio {
  margin-left: 5px;
  color: #0a7e7e;
}

.details {
  width: 678px;
  height: 259px;
  border: #004492 1px solid;
  overflow: hidden;
}
table {
  margin: auto;
}
.table {
  overflow-y: scroll;
  margin-top: 10px;
}
.table::-webkit-scrollbar {
  width: 3px;
  background-color: #0a7e7e;
}
.table::-webkit-scrollbar-track {
  background-color: #d6e2ed;
}
.table::-webkit-scrollbar-thumb {
  background: #004492;
}
.distinguish {
  border-bottom: 1px dashed #7f7f7f;
}
/deep/ .el-table__row /deep/ .expanded {
  border: 1px solid red;
}
/deep/ .el-table__row {
  color: #004492;
  border: 1px solid red;
}
.tips {
  float: left;
  overflow: hidden;
  width: 376px;
  height: 50px;
  border: #004492 1px solid;
  margin-top: 15px;
  margin-left: 4px;
}
.tips li {
  float: left;
  margin-left: 36px;
  line-height: 50px;
}
.tips :nth-child(1) span {
  display: inline-block;
  width: 12px;
  height: 12px;
  background-color: #39ca66;
  margin-right: 10px;
  vertical-align: middle;
}
.tips :nth-child(2) span {
  display: inline-block;
  width: 12px;
  height: 12px;
  background-color: #fe5958;
  margin-right: 10px;
  vertical-align: middle;
}
.tips :nth-child(3) span {
  display: inline-block;
  width: 12px;
  height: 12px;
  background-color: #ffcb58;
  margin-right: 10px;
  vertical-align: middle;
}
.tips :nth-child(4) span {
  display: inline-block;
  width: 12px;
  height: 12px;
  background-color: #808080;
  margin-right: 10px;
  vertical-align: middle;
}

.Choice {
  margin-top: 15px;
  width: 678px;
  height: 50px;
  border: #39ca66 1px solid;
  margin-left: 400px;
  overflow: hidden;
  line-height: 50px;
}
.Choice .el-radio {
  margin-left: 115px;
}
.pagesKG {
  margin-top: 10px;
  text-align: center;
}
.pagesDJ {
  float: left;
  margin-top: 15px;
  width: 348px;
  height: 30px;
  margin-left: 200px;
  overflow: hidden;
  padding-top: 8px;
}
thead th,
tr {
  width: 110px;
  height: 30px;
}
table {
  border-collapse: collapse;
  text-align: center;
}
.Demarcation {
  border-top: 2px solid #606266;
}
.color {
  color: #ffcb58;
}
.red {
  color: red;
}
.Contai_details {
  color: #333;
  margin-left: 9px;
}
.three :hover .Contai_details {
  cursor: pointer;
}
.rigth:hover {
  cursor: pointer;
}
.disabled {
  display: inline-block;
  margin-right: 10px;
}
.search {
  padding-left: 5px;
}
.search input {
  width: 260px;
  height: 30px;
  outline: none;
  padding-left: 10px;
}
.search .el-button {
  padding: 8px 6px;
  margin-left: 10px;
}
.rigth .el-button {
  padding: 2px 10px;
}
.rigth > div {
  display: inline-block;
  /* margin-right: 10px; */
}
.rigth .el-slider {width: 100px;}
.Full {
  float: right;
}
.Full .el-button {
  padding: 3px;
}
.mg {
  margin-left: 10px;
}
.el-slider {
  /* display: inline-block; */
}
</style>
